#include "ObMoving.h"

float ObMoving::DEFAULTSPEED_X = 60.0f;
float ObMoving::DEFAULTSPEED_Y = 100.0f;

ObMoving::ObMoving(){
	MAX_VELOCITYX = 0.0f;
	MAX_VELOCITYY = 0.0f;

	XAXISGRAVITY = 1.5f;
	YAXISGRAVITY = -1500.0f;

	mAcceleration	= D3DXVECTOR3(0.0f,0.0f,0.0f);
	mVelocity		= D3DXVECTOR3(0.0f,0.0f,0.0f);
	mIsYGravity		= true;
	mIsXGravity		= false;
	mIsTurnAround	= false;
	mIsJump			= false;
	mUpdateMoving	= true;
}

void ObMoving::updateMoving(float dt, float dtx, float dty){

	if(mUpdateMoving == false) return;

	mVelocity.x += mAcceleration.x*dtx;
	mVelocity.y += mAcceleration.y*dty;

	if(mVelocity.x > MAX_VELOCITYX){
		mVelocity.x = MAX_VELOCITYX;
	}

	if(mVelocity.x < -MAX_VELOCITYX){
		mVelocity.x = -MAX_VELOCITYX;
	}

	if(MAX_VELOCITYY != 0.0f && mVelocity.y > MAX_VELOCITYY){
		mVelocity.y = MAX_VELOCITYY;
	}

	if(MAX_VELOCITYY != 0.0f && mVelocity.y < -MAX_VELOCITYY){
		mVelocity.y = -MAX_VELOCITYY;
	}

	mPos.x+= mVelocity.x*dtx;
	mPos.y+= mVelocity.y*dty;

	if(mIsXGravity){
		mVelocity.x -= XAXISGRAVITY*mVelocity.x*dtx;
	}

	if(mIsYGravity){
		mVelocity.y += YAXISGRAVITY*dty;
	}
}

void ObMoving::setIsJump(bool isjump){
	mIsJump = isjump;
}

void ObMoving::setAcceleration(D3DXVECTOR3& accel){
	mAcceleration = accel;
}
void ObMoving::setVelocity(D3DXVECTOR3& vel){
	mVelocity = vel;
}
void ObMoving::isXAxisGravity(bool enable){
	mIsXGravity = enable;
}
void ObMoving::isYAxisGravity(bool enable){
	mIsYGravity = enable;
}
void ObMoving::isTurnAround(bool enable){
	mIsTurnAround = enable;
}

D3DXVECTOR3& ObMoving::getAcceleration(){
	return mAcceleration;
}
D3DXVECTOR3& ObMoving::getVelocity(){
	return mVelocity;
}
bool ObMoving::getXAxisGravity(){
	return mIsXGravity;
}
bool ObMoving::getYAxisGravity(){
	return mIsYGravity;
}
bool ObMoving::getIsTurnAround(){
	return mIsTurnAround;
}

